package com.zhang.yygh.task.job;

import com.zhang.yygh.mq.MqConst;
import com.zhang.yygh.mq.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    //cron表达式：
    @Scheduled(cron = "*/20 * * * * ?")
    public void printTime(){
        /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new Date());
        System.out.println(format);*/

        System.out.println(new Date().toLocaleString());
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_ITEM, "xx");
    }
}
